package com.pd;

import com.pd.pojo.PdOrder;
import com.pd.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/*
spring 封装的rabbitmq api，
接收消息不用写代码，而是通过注解配置
 */
@RabbitListener(queues = "orderQueue")
@Component
public class OrderConsumer {
    @Autowired
    private OrderService orderService;

    //配合@RabbitListener，指定处理消息的方法
    @RabbitHandler
    public void receive(PdOrder order) throws Exception {
        orderService.saveOrder(order);
        System.out.println("------------------------------订单已存储");
    }
}
